﻿using System;
using System.Collections.Generic;
using System.Text;

namespace DPortAck.ObjectModel
{
    public class MachineConnectionTest
    {
        private ConnectionTest _test;
        private List<MachinePortConnectionTest> _portTests;

        public ConnectionTest Test
        {
            get { return _test; }
            set { _test = value; }
        }

        public String Host { get; set; }

        public void AddPortTest(MachinePortConnectionTest portTest)
        {
            if (portTest == null)
                throw new ArgumentNullException("portTest");

            if (_portTests == null)
                _portTests = new List<MachinePortConnectionTest>();

            portTest.Machine = this;
            _portTests.Add(portTest);
        }

        public MachineConnectionTestResult Execute()
        {
            MachineConnectionTestResult result = new MachineConnectionTestResult(this);
            result.Succeded = true;

            if (_portTests != null && _portTests.Count > 0)
            {
                foreach (MachinePortConnectionTest portTest in _portTests)
                {
                    MachinePortConnectionTestResult portTestResult = portTest.Execute();

                    if (!portTestResult.Succeded)
                        result.Succeded = false;

                    result.AddTestResult(portTestResult);
                }
            }

            return result;
        }
    }
}
